package www.dianbaozu.com.ui.chat.friend.adapter

import androidx.recyclerview.widget.RecyclerView
import com.netease.nim.uikit.R
import com.netease.nim.uikit.api.NIMHelper
import www.dianbaozu.com.ui.chat.friend.holder.FriendTopViewHolder
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemQuickAdapter
import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder
import www.dianbaozu.com.ui.chat.friend.holder.FriendUserViewHolder
import www.wen.com.common.lib.data.entities.FriendEntity

class FriendAdapter(recyclerView: RecyclerView, data: List<FriendEntity>) :
    BaseMultiItemQuickAdapter<FriendEntity, BaseViewHolder>(recyclerView, data) {

    companion object {
        const val VIEW_TYPE_TOP = 1
        const val VIEW_TYPE_ONLINE = 2
        const val VIEW_TYPE_OFFLINE = 3
    }

    init {
        addItemType(VIEW_TYPE_TOP, R.layout.item_friends, FriendTopViewHolder::class.java)
        addItemType(VIEW_TYPE_ONLINE, R.layout.item_friends, FriendUserViewHolder::class.java)
        addItemType(VIEW_TYPE_OFFLINE, R.layout.item_friends, FriendUserViewHolder::class.java)
    }

    override fun getViewType(item: FriendEntity): Int =
        if (item.topEntity != null) {
            VIEW_TYPE_TOP
        } else {
            if (NIMHelper.accountIsOnline(item.friend?.account ?: "")) {
                VIEW_TYPE_ONLINE
            } else {
                VIEW_TYPE_OFFLINE
            }
        }

    override fun getItemKey(item: FriendEntity?): String =
        item.toString()
}